package cn.edu.scau.cmi.shishuai.exercise10;

public class EncryptAndDecrypt {
	String encrypt(String source, String pass) {
		char[] p = pass.toCharArray();
		int n = p.length;
		char[] c = source.toCharArray();
		int m = c.length;
		for (int i = 0; i < m; i++) {
			int mima = c[i] + p[i % n];
			c[i] = (char) mima;
		}
		return new String(c);
	}
	String decrypt (String source, String pass) {
		char[] p = pass.toCharArray();
		int n = p.length;
		char[] c = source.toCharArray();
		int m = c.length;
		for (int k = 0; k < m; k++) {
			int mima = c[k] - p[k % n];
			c[k] = (char)mima;
		}
		return new String(c);
	}
}
